import { createPinia, defineStore } from "pinia";
import piniaPersistConfig from "@/config/piniaPersist";
import piniaPluginPersistedstate from "pinia-plugin-persistedstate";

export const GlobalStore = defineStore({
  id: "GlobalStore",
  state: () => ({
    showLogin: false,
  }),
  getters: {},
  actions: {
    closeShowLogin() {
      this.showLogin = false;
    },
    openShowLogin() {
      this.showLogin = true;
    },
  },
});

export const PersistentStore = defineStore({
  id: "PersistentStore",
  state: () => ({
    theme: "light",
    themeDarkColor: "#333",
    themeLightColor: "#f4f4f4",
    token: "",
    userInfo: {},
    songListInfo: {
      id: "",
      index: 0,
      list: [],
    },
    videoId: "",
  }),
  getters: {},
  actions: {
    editIndex(e) {
      this.songListInfo.index = e;
    },
    setSongListInfo(e) {
      this.songListInfo = e;
    },
    setToken(e) {
      this.token = e;
    },
    setUserInfo(e) {
      this.userInfo = e;
    },
    setVideoId(e) {
      this.videoId = e;
    },
  },
  persist: piniaPersistConfig("PersistentStore"),
});

const pinia = createPinia();
pinia.use(piniaPluginPersistedstate);

export default pinia;
